import lombok.extern.slf4j.Slf4j;
import org.lanettiesso.dubbo.simple.annotation.Service;
import org.lanettiesso.dubbo.simple.consumer.controller.HelloController;
import org.lanettiesso.dubbo.simple.registry.MemoryRegistryCenter;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Map;

@Slf4j
public class SpringRunner {

    public static void main(String[] args) {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
        context.start();

        Map<String, Object> dubboServiceMap = context.getBeansWithAnnotation(Service.class);
        dubboServiceMap.forEach((beanName, service) -> {
            MemoryRegistryCenter.registryProvider(service.getClass(), service);
            log.info("register provider: " + beanName);
        });

        HelloController helloController = context.getBean(HelloController.class);
        System.out.println(helloController.getTime());
        System.out.println(helloController.sayHello("lan"));
    }
}
